package zkdemo;

import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.retry.ExponentialBackoffRetry;
import org.apache.curator.utils.ZKPaths;
import org.apache.zookeeper.ZooKeeper;
import org.junit.Before;
import org.junit.Test;

public class Curator_ZKPaths {
	CuratorFramework client;
	
	@Before
	public void init() {
		client = CuratorFrameworkFactory.builder()
				.connectString("192.168.10.188:2181")
				.sessionTimeoutMs(5000)
				.connectionTimeoutMs(3000)
				.retryPolicy(new ExponentialBackoffRetry(1000, 3))
				.namespace("zk-book")
				.build();
		client.start();
	}
	
	@Test
	public void test() throws Exception {
		ZooKeeper zk = client.getZookeeperClient().getZooKeeper();
		String path = ZKPaths.fixForNamespace("/zkpath", "/sub");
		System.out.println("path="+path);
		path = ZKPaths.makePath("/zkpath", "/sub");
		System.out.println("path="+path);
		
		ZKPaths.mkdirs(zk, ZKPaths.fixForNamespace("/zk-book", "/zkpath"));
	}
}
